package com.tencent.web.controller;

import com.github.pagehelper.PageInfo;
import com.tencent.constant.MessageConstant;
import com.tencent.entity.*;
import com.tencent.service.CheckItemService;
import jdk.nashorn.internal.ir.annotations.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: aiming    @date: 2022/8/12 20:10
 * @description: 检查项管理
 */
@RestController
@RequestMapping("/checkitem")
public class CheckItemController {
    @Autowired//查找服务
    private CheckItemService checkItemService;

    //新增检查项
    @RequestMapping("/add")
    public Result add(@RequestBody Checkitem checkItem){
        try {
            checkItemService.add(checkItem);
        }catch (Exception e){
            e.printStackTrace();
            //服务调用失败
            return Result.error(MessageConstant.ADD_CHECKITEM_FAIL);
        }
        return Result.success(null);
    }


    //检查项分页查询
    @RequestMapping("/findPage")
    public Result findPage(Pagination pagination){
        PageInfo<Checkitem> checkitemPageInfo = checkItemService.pageQuery(pagination);
        return Result.success(checkitemPageInfo);
    }
//    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
//        PageResult pageResult = checkItemService.pageQuery(queryPageBean);
//        return pageResult;
//    }


    //删除检查项
    @RequestMapping("/delete")
    public Result delete(Integer id){
        try {
            checkItemService.deleteById(id);
        }catch (Exception e){
            e.printStackTrace();
            //服务调用失败
            return Result.error(MessageConstant.DELETE_CHECKITEM_FAIL);
        }
        return Result.success(null);
    }


    //编辑检查项
    @RequestMapping("/edit")
    public Result edit(@RequestBody Checkitem checkitem){
        try {
            checkItemService.edit(checkitem);
        }catch (Exception e){
            e.printStackTrace();
            //服务调用失败
            return Result.error(MessageConstant.EDIT_CHECKITEM_FAIL);
        }
        return Result.success(null);
    }


    //编辑检查项
    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
            Checkitem checkitem = checkItemService.findById(id);
            return Result.success(checkitem);
        }catch (Exception e){
            e.printStackTrace();
            //服务调用失败
            return Result.error(MessageConstant.QUERY_CHECKITEM_FAIL);
        }
//        return Result.success(null);
    }


}
